// pages/ks/ks.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
      scoreList: [{
          name: 'java',
          score: 50,
          username: '小黑'
      }, {
          name: 'mysql',
          score: 80,
          username: '小红'
      }, {
          name: 'vue',
          score: 100,
          username: '黑大帅'
      }],
      newscore:{
          name: '',
          score: 0,
          username: ''
      },
      name:'',
      score:'',
      username:'',
      count:'',
      min:'',
  },
  remdata(){
     this.setData({
         name:"",
         score:"",
         username:""
     })
  },
  addcj(){
      let res =  Object.assign(
          [...this.data.scoreList,{name:this.data.name,score:this.data.score,username:this.data.username}])
      this.setData({
          scoreList:res
      })
      wx.showToast({
        title: '添加成功',
        icon:'success'
      })
      this.remdata()
      this.setcount()
      this.setmin()
  },
  deleteuser(index){
      console.log();
      this.data.scoreList.splice(index.target.dataset.index,1)
      this.setData({
          scoreList:this.data.scoreList
      })
      wx.showToast({
        title: '删除成功',
        icon:'error'
      })
     this.setcount()
     this.setmin()
  },
  login(){
      wx.navigateTo({
        url: '/pages/home1/home1',
      })
  },
  setcount(){
      this.setData({
          count:this.data.scoreList.filter(item=>{
              return item.score>=60
          }).reduce(function (perv,cur){
              return Number(perv)+Number(cur.score)
          },0)
  
         })
  },
  setmin(){
    this.setData({
      min:this.data.scoreList.filter(item => {
        return item.score<60
      }).length
    })
    console.log(this.data.min);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
      this.setcount();
      this.setmin()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

})